$(function(){
	
	$.post("dep_dep.action", function(data) {
		var d = (data.deps).split(',');
		$("#usli_redo_dep").empty();
		$("<option value='0'>全部</option>").appendTo("#usli_redo_dep");
        $.each(d,function(){  
        	$("<option value="+this+">"+this+"</option>").appendTo("#usli_redo_dep");
        });
	});
	
	$("#redo_result").datagrid({
          url: "redo_redo_list.action",
          //method:'post',
          iconCls: "icon-edit",
	      title: "订单列表",
          loadMsg:"数据装载中....",
          striped: true,//条纹
	      fitColumns: true,//自动调整单元格宽度
	      rownumbers: true,//显示行号
	      singleSelect: false,//单选
	      pagination: true,//分页
	      queryParams: {
		   "page.dep": {"id":"usli_redo_dep","type":"text"},
		   "page.begin_time": {"id":"usli_redo_begin_time","type":"datebox"},
		   "page.end_time": {"id":"usli_redo_end_time","type":"datebox"},
		  },
		  paramsName: {
	    	page: "page.page",
	    	num: "page.num"
	      },
	      toolbar: '#usli_redo',
          columns:[[
                    {title:'订单号',field:'companyNum',width:40},    
                    {title:'部门',field:'department',width:20},
                    {title:'重做次数',field:'redoNum',width:30},
				]],
         view: detailview,  
         detailFormatter:function(index,row){  
             return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>';  
         },  
         onExpandRow: function(index,row){  
             $('#ddv-'+index).datagrid({  
                 url: "redo_redo_see.action?companyNum="+row.companyNum+"&department="+row.department+"",  
                 fitColumns:true,  
                 singleSelect:true,  
                 rownumbers:true,  
                 loadMsg:'',  
                 height:'auto',  
                 columns:[[  
	                 {title:'ID',field:'dep',width:30},    
                     {title:'到达时间',field:'regtime',width:30},
                     {title:'离开时间',field:'outtime',width:30},
                 ]],  
                 onResize:function(){  
                     $('#redo_result').datagrid('fixDetailRowHeight',index);  
                 },  
                 onLoadSuccess:function(){  
                     setTimeout(function(){  
                         $('#redo_result').datagrid('fixDetailRowHeight',index);  
                     },0);  
                 }  
             });  
             $('#redo_result').datagrid('fixDetailRowHeight',index);  
         } 
     });

	
});	


function redo_stat_show() {
	var dep = $("#usli_redo_dep").val();
	var begin_time = $("#usli_redo_begin_time").datebox('getValue');
	var end_time = $("#usli_redo_end_time").datebox('getValue');
	var colorArray = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
	
	$.post("redo_redo_stat.action", {"department":dep,"begin_time":begin_time,"end_time":end_time}, function(data) {
		
		$("#redo_stat_dd").dialog({width:616*data.n});
		
		var myData=eval(data.rows);
		var myChart = new JSChart('redo_stat_dd', 'bar');
		var colors = [];
		$.each(myData, function() {
			var colorTag = "#";
			for (var i = 0; i<6; i++){
				colorTag+=colorArray [Math.round(Math.random()*15)];
			}
			colors.push(colorTag);
		});
		
		myChart.setDataArray(myData);
		myChart.colorizeBars(colors);
		myChart.setTitle(data.title);
		myChart.setTitleColor('#8E8E8E');
		myChart.setAxisNameX(data.x);
		myChart.setAxisNameY('次数');
		myChart.setAxisColor('#c6c6c6');
		myChart.setAxisWidth(1);
		myChart.setAxisNameColor('#9a9a9a');
		myChart.setAxisValuesColor('#939393');
		myChart.setAxisPaddingTop(60);
		myChart.setAxisPaddingLeft(50);
		myChart.setAxisPaddingBottom(60);
		myChart.setTextPaddingBottom(20);
		myChart.setTextPaddingLeft(15);
		myChart.setTitleFontSize(18);
		myChart.setAxisNameFontSize(12);
		myChart.setAxisValuesFontSize(9);
		myChart.setBarValuesFontSize(9);
		myChart.setBarBorderWidth(0);
		myChart.setBarSpacingRatio(50);
		myChart.setBarValuesColor('#737373');
		myChart.setGrid(false);
		myChart.setSize(616*data.n, 321);
		myChart.setBackgroundImage('images/chart_bg.jpg');

		myChart.draw();
	});
}


function redo_load() {
	$('#redo_result').datagrid('reload');
}


function formSubmit() {
	$("#afupmes").html("");
	$("#loading").show();
	uploadbutton.submit();
}



